Thread: [Inheritance Hierarchy] User Input on program with constructors. How ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    4

    Question [Inheritance Hierarchy] User Input on program with constructors. How ?

    Hie there everyone, i'm currently working on my assignment on Inheritance Hierarchy. I managed to construct everything, the program is fully working without any problem.

    BUT now i need to make a user input based program instead of test program like what i've done. Its like, the user can input the receiver and sender name and informations. I thought this would be the easiest part but damn.. i'm trying everything i know trying to link the >>cin to the constructors above but none are working. Everything giving me error. Again and again.. errors.. errors.. errors..

    Please help me. Any idea how to do it ? An example on how to create a user input for atleast the sender's name in this program would be very very much appreciated. The rest i can do it myself.

    Thanks.


    Code:
    #include <iostream>
    #include <iomanip>
    #include <string>
    
    
    using namespace std;
    
    
    class Package
    {
          
     public:
    // constructor initiliazes data members
    
                   Package( const string &, const string &, const string &, 
                   const string &, int, const string &, const string &, const string &, 
                   const string &, int, double, double );
    
                   void setSenderName( const string & ); 
                   string getSenderName() const;
    
                   void setSenderAddress( const string & );
                   string getSenderAddress() const; 
    
                   void setSenderCity( const string & ); 
                   string getSenderCity() const; 
    
                   void setSenderState( const string & ); 
                   string getSenderState() const; 
    
                   void setSenderZIP( int ); 
                   int getSenderZIP() const; 
    
                   void setRecipientName( const string & ); 
                   string getRecipientName() const; 
    
                   void setRecipientAddress( const string & ); 
                   string getRecipientAddress() const; 
    
                   void setRecipientCity( const string & ); 
                   string getRecipientCity() const; 
    
                   void setRecipientState( const string & ); 
                   string getRecipientState() const; 
    
                   void setRecipientZIP( int ); 
                   int getRecipientZIP() const; 
    
                   void setWeight( double ); 
                   double getWeight() const; 
    
                   void setCostPerOunce( double ); 
                   double getCostPerOunce() const; 
    
                   virtual double calculateCost() const; 
                   
     private:
    // data members to store sender and recipient's address information
    
                   string senderName;
                   string senderAddress;
                   string senderCity;
                   string senderState;
                   int senderZIP;
                   string recipientName;
                   string recipientAddress;
                   string recipientCity;
                   string recipientState;
                   int recipientZIP;
    
                   double weight; // weight of the package
                   double costPerOunce; // cost per ounce to ship the package
    
    };
    
    //-----------------------------------------------------------------------------------------------------------//
    
    class OvernightPackage : public Package
    {
          
     public:
           
           OvernightPackage( const string &, const string &, const string &, const string &, int, 
           const string &, const string &, const string &, const string &, int, double, double, double );
                   
           void setOvernightFeePerOunce( double ); 
           double getOvernightFeePerOunce() const; 
           virtual double calculateCost() const; 
     
     private:
           
           double overnightFeePerOunce; // fee per ounce for overnight delivery
           
    }; // end class OvernightPackage
    
    
    //-----------------------------------------------------------------------------------------------------------//
    
    
    // OvernightPackage constructor
    OvernightPackage::OvernightPackage( const string &sName, const string &sAddress, const string &sCity, 
    const string &sState, int sZIP, const string &rName, const string &rAddress, const string &rCity, 
    const string &rState, int rZIP, double w, double cost, double fee ) : Package( sName, sAddress, sCity, 
    sState, sZIP, rName, rAddress, rCity, rState, rZIP, w, cost )
    
    .
    ..
    ...
    
    //-----------------------------------------------------------------------------------------------------------//
    
    
    class TwoDayPackage : public Package
    {
          
     public:
           
           TwoDayPackage( const string &, const string &, const string &, const string &, int, 
           const string &, const string &, const string &, const string &, int, double, double, double );
    
           void setFlatFee( double ); 
           double getFlatFee() const; 
    
           virtual double calculateCost() const; 
    
     private:
             
            double flatFee; 
            
    }; 
    
    
    //-----------------------------------------------------------------------------------------------------------//
    
    
    // TwoDayPackage constructor
    TwoDayPackage::TwoDayPackage( const string &sName, const string &sAddress, 
    const string &sCity, const string &sState, int sZIP, const string &rName, const string &rAddress, 
    const string &rCity, const string &rState, int rZIP, double w, double cost, double fee ) 
    : Package( sName, sAddress, sCity, sState, sZIP, rName, rAddress, rCity, rState, rZIP, w, cost )
    
    .
    ..
    ...
    
    
    
    //-----------------------------------------------------------------------------------------------------------//
    
    
    // Package constructor initiliazes data members
    Package::Package( const string &sName, const string &sAddress, const string &sCity, const string &sState, 
    int sZIP, const string &rName, const string &rAddress, const string &rCity, const string &rState, int rZIP, 
    double w, double cost ) : senderName( sName ), senderAddress( sAddress ), senderCity( sCity ), 
    senderState( sState ), senderZIP( sZIP ), recipientName( rName ), recipientAddress( rAddress ), 
    recipientCity( rCity ), recipientState( rState ), recipientZIP( rZIP )
    
    .
    ..
    ...
    
    //-----------------------------------------------------------------------------------------------------------//
     
         
    int main()
    {
    
    //This is the test program
    OvernightPackage NightDeliver("Micheal", "Dr Rajkumar Road", "Rajajinagar Stage II", 
    "Bangalore", 12345, "Mathan", "Manjunath Road", "Berhampur", "Orissa", 54321, 16.00, 1.00, .25 );
    
    TwoDayPackage DayDeliver("Kamal", "Amravati Road", "Nagpur", "Maharashtra", 33333, 
    "Rajan", "Vijayawada Road", "Ansari Nagar", "New Delhi", 44444, 10.5, .65, 2.0 );
    cout << fixed << setprecision(2);             
    
    
    cout << "Customers for overnight delivery\n";
    cout << "\n";
    
    cout << "The sender :\n" << NightDeliver.getSenderName()<< "\n";
    cout << NightDeliver.getSenderAddress() << "\n";
    cout << NightDeliver.getSenderCity() << " " << NightDeliver.getSenderState() << " " 
    << NightDeliver.getSenderZIP() << "\n";
    cout << "\n";
    
    cout << "The recipient :\n" << NightDeliver.getRecipientName()<< "\n";
    cout << NightDeliver.getRecipientAddress() << "\n";
    cout << NightDeliver.getRecipientCity() << " " << NightDeliver.getRecipientState() << " " 
    << NightDeliver.getRecipientZIP() << "\n";
    cout << "The cost is $ " << NightDeliver.calculateCost() << "\n";
    
    cout << "\n\n";
    
    cout << "Customers for 2 days delivery\n";
    cout << "\n";
    
    cout << "The sender :\n" << DayDeliver.getSenderName()<< "\n";
    cout << DayDeliver.getSenderAddress() << "\n";
    cout << DayDeliver.getSenderCity() << " " << DayDeliver.getSenderState() << " " 
    << DayDeliver.getSenderZIP() << "\n";
    cout << "\n";
    
    cout << "The recipient :\n" << DayDeliver.getRecipientName()<< "\n";
    cout << DayDeliver.getRecipientAddress() << "\n";
    cout << DayDeliver.getRecipientCity() << " " << DayDeliver.getRecipientState() << " " 
    << DayDeliver.getRecipientZIP() << "\n";
    cout << "The cost is $ " << DayDeliver.calculateCost() << "\n";
    cout << "\n\n";
    
    
    system ("pause");
    return 0;
    
    }
    Last edited by chandreu; 04-25-2008 at 02:28 PM. Reason: Re-edited(removed some part of the code) again to protect from code theft by lazy arses.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  2. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  3. SSH Hacker Activity!! AAHHH!!
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-06-2005, 03:53 PM